home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTimer.z / RWTimer
Encoding:
Text File  |  2002-10-03  |  4.1 KB  |  133 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTiiiimmmmeeeerrrr((((3333CCCC++++++++))))                                                    RRRRWWWWTTTTiiiimmmmeeeerrrr((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTimer - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/timer.h>
  13.  
  14.  
  15.  
  16.               RWTimer timer;
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      This class can measure elapsed CPU (user) time.  The timer has two
  23.      states: running and stopped.  The timer measures the total amount of time
  24.      spent in the "running" state since it was either constructed or reset.
  25.      The timer is put into the "running" state by calling member function
  26.      ssssttttaaaarrrrtttt(((()))).  It is put into the "stopped" state by calling ssssttttoooopppp(((()))). RRRRWWWWTTTTiiiimmmmeeeerrrr
  27.      uses the system-dpendent function cccclllloooocccckkkk(((()))) which returns the number of
  28.      "ticks" since it was first called.  As a result, RRRRWWWWTTTTiiiimmmmeeeerrrr will not be able
  29.      to measure intervals longer than some system-dependent value.  (For
  30.      instance, on several common UNIX systems, this value is just under 36
  31.      minutes.)
  32.  
  33. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  34.      None
  35.  
  36. EEEExxxxaaaammmmpppplllleeee
  37.      This example prints out the amount of CPU time used while looping for 5
  38.      seconds (as measured using class RRRRWWWWTTTTiiiimmmmeeee).
  39.  
  40.               #include <rw/timer.h>
  41.  
  42.  
  43.  
  44.               #include <rw/rwtime.h>
  45.           #include <rw/rstream.h>
  46.           main()
  47.           {RWTimer t;
  48.            t.start();                 // Start the timer
  49.            RWTime start;
  50.            start.now();               // Record starting time
  51.            // Loop for 5 seconds:
  52.            for (RWTime current; current.seconds() - start.seconds() < 5;
  53.                 current = RWTime::now())
  54.            {;}
  55.            t.stop();                  // Stop the timer
  56.            cout << t.elapsedTime() << endl;
  57.            return 0;
  58.           }
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTiiiimmmmeeeerrrr((((3333CCCC++++++++))))                                                    RRRRWWWWTTTTiiiimmmmeeeerrrr((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.      PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt ((((eeeexxxxaaaacccctttt vvvvaaaalllluuuueeee mmmmaaaayyyy ddddiiiiffffffffeeeerrrr))))::::
  75.  
  76.               5.054945
  77.  
  78.  
  79.  
  80. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  81.  
  82.  
  83.  
  84.  
  85.               RRRRWWWWTTTTiiiimmmmeeeerrrr();
  86.  
  87.  
  88.      Constructs a new timer.  The timer will not start running until ssssttttaaaarrrrtttt(((())))
  89.      is called.
  90.  
  91. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  92.               double
  93.           eeeellllaaaappppsssseeeeddddTTTTiiiimmmmeeee() const;
  94.  
  95.  
  96.      Returns the amount of (CPU) time that has accumulated while the timer was
  97.      in the running state.
  98.  
  99.               void
  100.           rrrreeeesssseeeetttt();
  101.  
  102.  
  103.      Resets (and stops) the timer.
  104.  
  105.               void
  106.           ssssttttaaaarrrrtttt();
  107.  
  108.  
  109.      Puts the timer in the "running" state.  Time accumulates while in this
  110.      state.
  111.  
  112.               void
  113.           ssssttttoooopppp();
  114.  
  115.  
  116.      Puts the timer in the "stopped" state.  Time will not accumulate while in
  117.      this state.
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.